package edu.biwu.filter;

import jakarta.servlet.*;

import java.io.IOException;

/**
 * Filter的生命周期
 *  public void init(FilterConfig filterConfig):初始化过滤器
 *  public void destroy():销毁过滤器
 *
 *    1.当服务器启动时，会根据WEB.xml中的配置，初始化该过滤器(利用init()方法)
 *    2.当tomcat关闭时，过滤器被自动销毁(利用destroy()方法)
 */
public class FilterDemo03 implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println(this + "被初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println(this+"开始执行");
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println(this+"结束执行");
    }

    @Override
    public void destroy() {
        System.out.println(this + " 被销毁");
    }


}
